<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>游记明细</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travelContent.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/common.js"></script>


    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem('user'));
            //获取游记id------------------------------------------------
            //引入文件common.js中的方法,表示获得当前路径的?号之后的数据,自动包装成数组
            var params = getParams();
            var id = params.id;
            if (id){
                //获取指定id的游记
                $.get("/travels/"+ id, function (data) {
                    //回显
                    $(".travels").renderValues(data,{
                        setPerson:function (item, value) {
                            var ret="";
                            if (value==1){
                                ret ="一个人的旅游"
                            }else if(value==2){
                                ret ="和父母"
                            }else if(value==3){
                                ret ="和朋友"
                            }else if(value==4){
                                ret ="和同事"
                            }else if(value==5){
                                ret ="和爱人"
                            }else if(value==6){
                                ret ="和其他"
                            }
                            $(item).html(ret);
                        }
                    });


                })
            }
            //---------------------------收藏 end------------------------------------------------
                if(user){

                    $.get("/travelCollection/get",{userId:user.id,travelId:id},function (data) {
                        if(data.success){
                            $('#collectBtn').css('color',"blue");

                        }
                    })

                }

            $('#collectBtn').click(function () {

                if(user){
                    $.get("/travelCollection/get",{userId:user.id,travelId:id},function (data) {

                        if(data.success){//表示已经收藏
                            $(document).dialog({
                                type: 'confirm',
                                content: '取消收藏?',
                                position: 'bottom',  // center: 居中; bottom: 底部
                                onClickConfirmBtn:function () {
                                  //删除操作
                                    $.post("/travelCollection/delete",{userId:user.id,travelId:id},function (data) {
                                        if (data.success){
                                            $('#collectBtn').css("color","gray");
                                            $(document).dialog({
                                                type : 'notice',
                                                infoText: '已取消收藏',
                                                autoClose: 1500,
                                                position: 'bottom'  // center: 居中; bottom: 底部
                                            });
                                        }
                                    })
                                }
                            });

                        }else {

                            //已经登陆,将用户id及游记id存入数据库
                            $.post("/travelCollection/save",{userId:user.id,travelId:id},function (data) {
                                if (data.success){
                                    //成功就改变样式
                                    $('#collectBtn').css('color',"blue");
                                    $(document).dialog({
                                        type : 'notice',
                                        infoText: '收藏成功',
                                        autoClose: 1500,
                                        position: 'bottom'  // center: 居中; bottom: 底部
                                    });

                                }else {
                                    alert(data.msg);
                                }
                            })
                        }
                    })

                }else {
                    //没登陆先去登陆
                    $(document).dialog({
                        type: 'confirm',
                        content: '亲,请先登录',
                        position: 'bottom',  // center: 居中; bottom: 底部
                        onClickConfirmBtn:function () {
                            window.location.href="/login.html";
                        }
                    });
                }
            })

            //end-----------------游记点赞事件的绑定-------------------------
            var travelId = getParams().id;
            var user = JSON.parse(sessionStorage.getItem('user'));
            var sourceId = user.id;
                console.log(travelId);
                $("#likeBtn").click(function () {
                    $.get("/travelLikes/" + travelId, function (data) {
                        if (data.data == 1) {
                            $("#likeBtn").addClass("red");
                        }else if (data.data == 0) {
                            $("#likeBtn").removeClass("red");
                        }
                    })
                })
            //进行回显操作
            $.get("/travelLikes/" + travelId + "/likecounts", function (data) {
                if (data.data == 1) {
                    $("#likeBtn").addClass("red");
                } else if (data.data == 0) {
                    $("#likeBtn").removeClass("red");
                }
            })
            //游记的评论操作-----------------------------------------------------------
            $("#commentBtn").click(function () {
                window.location.href="/pinglun.html?id="+travelId;
            })

        })


    </script>





    <style>
        .red {
            color: red;
        }
    </style>
</head>
<body>
<div class="demo"></div>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
        </div>
    </div>
</div>

<div class="travels">
    <img  class="cover" render-src="coverUrl">
    <div class="container">
        <h6 class="title" render-html="title"></h6>
        <small>
            <span render-html="travelTime"></span>
            浏览 <span> 0</span>
            回复 <span> 0</span>
        </small>
        <div class="row">
            <div class="col-2 img">
                <img  class="rounded-circle" render-src="author.headImgUrl">
            </div>
            <div class="col-6 mine">
                <small>
                    <span render-html="author.nickName"></span>
                    <button class="btn" id="followBtn"></button>
                    <br>
                    <span>0 </span>篇游记
                    <span>0 </span>粉丝
                </small>
            </div>
            <div class="attention col">
                <span class="addr" render-html="place.name"></span>
            </div>
        </div>
    </div>
    ,
    <div class="container">
        <fieldset>
            <legend>我的出行信息</legend>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-calendar"></i> 出发时间 <span render-html="travelTime"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-money"></i> 人均费用
                    <span render-html="perExpends"></span></div>
            </div>
            <div class="d-flex">
                <div class="p-2  flex-fill">
                    <i class="fa fa-user-circle"></i> 人物
                    <span render-fun="setPerson" render-key="person" id="person"></span>
                </div>
                <div class="p-2  flex-fill"><i class="fa fa-clock-o"></i> 出行天数
                    <span render-html="days"></span>
                </div>
            </div>
        </fieldset>

        <div class="content" render-html="travelContent.content">

        </div>
    </div>

    <hr>

    <div class="container d-flex">
        <div class="p-2  flex-fill">
            <article class="htmleaf-container">
            </article>
            <i class="fa fa-thumbs-o-up" id="likeBtn"></i>
        </div>
        <div class="p-2  flex-fill"><i class="fa  fa-commenting-o" id="commentBtn"> </i>
        </div>
        <div class="p-2  flex-fill"><i class="fa save fa-star-o " id="collectBtn"></i>
        </div>
    </div>
</div>



</body>

</html>